//
//  ZSVisitorView.m
//  微博-0C
//
//  Created by 周李波 on 16/7/20.
//  Copyright © 2016年 q. All rights reserved.
//

#import "ZSVisitorView.h"
#import "Masonry.h"

@interface ZSVisitorView ()

@property (nonatomic,weak)UIImageView *feedImageView;

@property (nonatomic,weak)UIImageView *maskImageView;

@property (nonatomic,weak)UIImageView *iconImageView;

@property (nonatomic,weak)UILabel *messageLabel;

@property (nonatomic,weak)UIButton *loginButton;

@property (nonatomic,weak)UIButton *regButton;

@end

@implementation ZSVisitorView
#pragma mark
#pragma mark - 按钮点击
- (void)buttonClick{
    if (self.visitorBlock) {
        self.visitorBlock();
    }
    
}

#pragma mark
#pragma mark - 初始化方法
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = RGBCOLOR(237, 237, 237);
//        self.backgroundColor = [UIColor whiteColor];
        [self setupUI];
        
    }
    return self;
}
#pragma mark
#pragma mark - 布局完成
- (void)layoutSubviews{
    [super layoutSubviews];
    [self setupLayout];
}
#pragma mark
#pragma mark - 设置UI
- (void)setupUI{
    UIImageView *feedImageView = [[UIImageView alloc]init];
    feedImageView.image = [UIImage imageNamed:@"visitordiscover_feed_image_smallicon"];
    [self addSubview:feedImageView];
    self.feedImageView = feedImageView;
    
    UIImageView *maskImageView = [[UIImageView alloc]init];
    maskImageView.image = [UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"];
    [self addSubview:maskImageView];
    self.maskImageView = maskImageView;
    
    UIImageView *iconImageView = [[UIImageView alloc]init];
    iconImageView.image = [UIImage imageNamed:@"visitordiscover_feed_image_house"];
    [self addSubview:iconImageView];
    self.iconImageView = iconImageView;
    
    UILabel *messageLabel = [[UILabel alloc]init];
    messageLabel.font = [UIFont systemFontOfSize:14];
    messageLabel.text = @"关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜";
    messageLabel.textAlignment = NSTextAlignmentCenter;
    messageLabel.numberOfLines = 0;
    messageLabel.textColor = [UIColor grayColor];
    [self addSubview:messageLabel];
    self.messageLabel = messageLabel;
    
    UIButton *loginButton = [[UIButton alloc]init];
    [self addSubview:loginButton];
    self.loginButton = loginButton;
    [loginButton setTitle:@"登陆" forState:UIControlStateNormal];
    loginButton.titleLabel.font = [UIFont systemFontOfSize:15];
//    loginButton.titleLabel.textColor = [UIColor orangeColor];
    [loginButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [loginButton setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
//    [loginButton sizeToFit];
    [loginButton addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *regButton = [[UIButton alloc]init];
    [self addSubview:regButton];
    self.regButton = regButton;
    [regButton setTitle:@"注册" forState:UIControlStateNormal];
    regButton.titleLabel.font = [UIFont systemFontOfSize:15];
//    regButton.titleLabel.textColor = [UIColor orangeColor];
    [regButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [regButton setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
//    [regButton sizeToFit];
    [regButton addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
    
}
#pragma mark
#pragma mark - 设置约束
- (void)setupLayout{
    [self.feedImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    [self.maskImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.equalTo(CGSizeMake(230, 36));
        make.width.equalTo(230);
        make.height.equalTo(36);
        make.top.equalTo(self.maskImageView.bottom).offset(16);
        make.centerX.equalTo(self);
        
    }];
    [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.messageLabel.leading);
        make.width.equalTo(100);
        make.height.equalTo(36);
        make.top.equalTo(self.messageLabel.bottom).offset(16);
        
    }];
    [self.regButton makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.messageLabel.trailing);
        make.top.equalTo(self.loginButton.top);
        make.size.equalTo(CGSizeMake(100, 36));
    }];
    
}
#pragma mark
#pragma mark - 暴露的方法判断
- (void)setupVisitViewInfo:(NSString *)imageName message:(NSString *)message{
    if (imageName && message) {
        self.iconImageView.image = [UIImage imageNamed:imageName];
        self.messageLabel.text = message;
        self.feedImageView.hidden = YES;
        
    }else{
        [self setupAnimation];
    }
}
- (void)setupAnimation{
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    
    animation.toValue = @(M_PI * 2);
    animation.repeatCount = MAXFLOAT;
    animation.duration = 10;
    animation.removedOnCompletion = NO;
    [self.feedImageView.layer addAnimation:animation forKey:nil];
}
@end
